package com.monicash.monicash.login;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.monicash.monicash.R;
import com.monicash.monicash.base.BaseActivity;
import com.monicash.monicash.information.CapitalInforActivity;
import com.monicash.monicash.util.T;

public class ResetPasswordActivity extends BaseActivity {

    TextView back;
    TextView right_text;

    EditText et_password;
    ImageView iv_look_up;
    EditText et_password_confirm;
    ImageView iv_look_up_confirm;
    TextView tv_button;
    TextView tv_runtime_error;

    private String password = "";
    private String password_confirm = "";
    private boolean look_up_confirm = false;
    private boolean look_up = false;



    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reset_password);
        initView();
        initData();

    }

    @Override
    public Activity getActivity() {
        return this;
    }

    @Override
    public void initView() {
        back = findViewById(R.id.back);
        right_text = findViewById(R.id.right_text);
        et_password = findViewById(R.id.et_password);
        iv_look_up = findViewById(R.id.iv_look_up);
        et_password_confirm = findViewById(R.id.et_password_confirm);
        iv_look_up_confirm = findViewById(R.id.iv_look_up_confirm);
        tv_button = findViewById(R.id.tv_button);
        tv_runtime_error = findViewById(R.id.tv_runtime_error);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        tv_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(TextUtils.isEmpty(password)){
                    T.showShort(getActivity(),"密码未输入");
                    return;
                }
                if(TextUtils.isEmpty(password_confirm)){
                    T.showShort(getActivity(),"密码未确认");
                    return;
                }
                finish();
            }
        });
        iv_look_up.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                look_up = !look_up;
                if(look_up){
                    et_password.setInputType(InputType.TYPE_CLASS_TEXT |
                            InputType.TYPE_TEXT_VARIATION_PASSWORD);
                }else {
                    et_password.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                }

            }
        });
        iv_look_up_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                look_up_confirm = !look_up_confirm;
                if(look_up_confirm){
                    et_password_confirm.setInputType(InputType.TYPE_CLASS_TEXT |
                            InputType.TYPE_TEXT_VARIATION_PASSWORD);
                }else {
                    et_password_confirm.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                }
            }
        });
        et_password.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                password = s.toString();
            }
        });

        et_password_confirm.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                password_confirm = s.toString();
                if(TextUtils.equals(password_confirm,password)){
                    tv_runtime_error.setVisibility(View.VISIBLE);
                }else {
                    tv_runtime_error.setVisibility(View.GONE);
                }

            }
        });

    }

    @Override
    public void initData() {

    }
}
